package com.itheima;

public class Testlambda {
    public static void main(String[] args) {
        testA();
        testB();
        testC();
        testD();
    }
    public static void testD(){
        D d1 = new D(){
            public int max(int a,int b){
                return Math.max(a,b);
            }
        };
        D d2 = (a,b) -> a > b ? a : b;
        D d3 =Math::max;
        int max = d3.max(1,2);
        System.out.println(max);
    }
    public static void testC(){
        //1.创建C接口匿名内部类对象
        C c1 = new C() {
            public String show(String name) {
                return "name ="+name;
            }
        };
        //2.创建C接口的Lambda表达式对象
        C c2 = name -> "name ="+name;
        //2.创建C接口的方法引用
        C c3 = Testlambda::show4;
        String result = c3.show("三");

    }

    public static String show4(String name){
        return "name ="+name;
    }
    public static void testB(){
        //1.创建B接口匿名内部类对象
        B b1 = new B() {
            public void show(String name) {
                System.out.println(name);
            }
        };
        //2.创建B接口的Lambda表达式对象
        B b2 = name -> System.out.println(name);
        //3.调用B接口的抽象方法
        B b3 =System.out::println;
        b3.show("李明同学");
    }
    public static void testA(){
        //1.创建A接口匿名内部类对象
        A a1 = new A() {
            public void show(String name,int age) {
                System.out.println(name+","+age);
            }
        };
        //2.将匿名内部类对象作改位Lambda表达式
        A a2 = (name, age)-> System.out.println(name+","+age);
        a2.show("张三", 18);
        //3.使用方法引用替换Lambda表达式
        A a3 = Testlambda::show2;
        a3.show("李四", 20);
        //4.使用静态方法引用替换Lambda表达式
        Testlambda  testLambda = new Testlambda();
        A a4 = Testlambda::show2;
        a4.show("王五", 20);
    }

    //3.定义一个成员方法，故意让返回类型是A接口
    public static void show2(String name, int age){
        System.out.println("show2:"+name+","+age);
    }

}